package com.hex.liyue.giftmodule.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.commonmodule.activity.BaseActivity;
import com.hex.liyue.commonmodule.utils.DateUtils;
import com.hex.liyue.commonmodule.utils.StatusBarCompatUtils;
import com.hex.liyue.giftmodule.adapter.AdapterDiscountDetails;
import com.hex.liyue.giftmodule.bean.DiscountDetailsBean;
import com.hex.liyue.giftmodule.presenter.DiscountDetailsPresenter;
import com.hex.liyue.giftmodule.presenter.IDiscountDetailsView;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 这是一个折现详情的界面
 * Created by WJ on 2016/6/20.
 */
public class DiscountDetailsActivity extends BaseActivity implements IDiscountDetailsView {
    @Bind(R.id.iv_toobar_back)
    ImageView ivToobarBack;
    @Bind(R.id.tv_toobar_title)
    TextView tvToobarTitle;
    @Bind(R.id.tv_discount_details_date)
    TextView mTvDate;
    @Bind(R.id.tv_discount_details_states)
    TextView mTvStates;
    @Bind(R.id.tv_discount_details_num)
    TextView mTvNums;
    @Bind(R.id.tv_discount_details_prices)
    TextView mTvPrices;
    @Bind(R.id.rv_shopping_list)
    RecyclerView rvShoppingList;
    @Bind(R.id.iv_icon)
    ImageView iv_icon;
    private DiscountDetailsPresenter discountDetailsPresenter;

    @Override
    protected void bindPresenter() {
        discountDetailsPresenter = new DiscountDetailsPresenter(this);
    }

    @Override
    protected void initData(Bundle extras) {
        String user_gift_cash_id = getIntent().getStringExtra("user_gift_cash_id");
        discountDetailsPresenter.getDiscountDetailsGifts(user_gift_cash_id);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_discount_details;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this);
        ivToobarBack.setVisibility(View.VISIBLE);
        tvToobarTitle.setText("折现详情");
    }

    @OnClick({R.id.iv_toobar_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_toobar_back:
                onBackPressed();
                break;
        }
    }

    @Override
    public void setAdapter(DiscountDetailsBean discountDetailsBean) {
        mTvDate.setText("折现时间：" + DateUtils.getFormatDate(discountDetailsBean.data.cash_time*1000, "yyyy-MM-dd"));
        mTvNums.setText("折现单号：" + discountDetailsBean.data.user_gift_cash_id);
        mTvPrices.setText("折现金额：￥" + discountDetailsBean.data.fact_cash);
        mTvStates.setText("折现状态：已折现");
        Glide.with(LiYueApplication.getInstance())
                .load(discountDetailsBean.data.gift_list.get(0).gift_url).centerCrop().error(R.drawable.no_icon)
                .into(iv_icon);
        rvShoppingList.setLayoutManager(new LinearLayoutManager(this));
        AdapterDiscountDetails adapterDiscountDetails = new AdapterDiscountDetails(discountDetailsBean.data.gift_list);
        adapterDiscountDetails.setOnItemClickListener(new AdapterDiscountDetails.OnItemClickListener() {
            @Override
            public void onItemClickListener(int position) {
//                Intent intent=new Intent(DiscountDetailsActivity.this, StoreDetailsActivity.class);
//                intent.putExtra("discountDetailsActivity","discountDetailsActivity");
//                intent.putExtra("gift_url",lists.get(position).gift_url);
//                startActivity(intent);
            }
        });
        rvShoppingList.setAdapter(adapterDiscountDetails);
    }

    @Override
    public void showLod(String msg) {
        showLoad(this, msg);
    }

    @Override
    public void closeLod() {
        closeLoad();
    }

    @Override
    public void showT(String msg) {
        showToast(this, msg);
    }
}
